package org.example;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class Testm {
    public static void main(String[] args) throws Exception {
        //注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        //获取数据的连接
        Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/maven_test",
                "root","root");
        String sql = "select  * from user";
        //向user表增加数据
        String sql1 = "insert into user(id,name,age,school) value(5,'于明勤',21,'柳州工学院')";
        String sql2 = "delete from user where id=2";
        //修改user表的数据
        String sql3 = "update user set age = 21 where id = 5";
        PreparedStatement pstmt = conn.prepareStatement(sql);
        System.out.println("=========增加=========");
        System.out.println();
        pstmt.executeUpdate(sql1);
        System.out.println("=========删除=========");
        System.out.println();
        pstmt.executeUpdate(sql2);
        System.out.println("=========修改=========");
        System.out.println();
        pstmt.executeUpdate(sql3);
        ResultSet res = pstmt.executeQuery();
        System.out.println("=======user表原数据========");
        while(res.next()){
            System.out.print(res.getInt("id")+"\t");
            System.out.print(res.getString("name")+"\t");
            System.out.print(res.getInt("age")+"\t");
            System.out.print(res.getString("school")+"\t");
            System.out.println();
        }

        res.close();

    }
}